package com.guaoran.interview.in2018.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author : guaoran
 * @Description : <br/>
 * @date :2018/12/13 17:46
 */
public class ExecutorsDemo implements Runnable{
    public static void main(String[] args) {
//        ExecutorService executorService = null;
//        //创建一个固定的线程池,负载比较大的
//        executorService = Executors.newFixedThreadPool(1);
//        //创建只有一个线程的线程池
//        executorService = Executors.newSingleThreadExecutor();
//        //创建一个不限制最大线程数
//        executorService = Executors.newCachedThreadPool();
//        //定时器，延时执行的线程池
//        executorService = Executors.newScheduledThreadPool(1);

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 100; i++) {
            executorService.submit(new ExecutorsDemo());
//            executorService.execute();
        }
        executorService.shutdown();

    }


    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }

}
